home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
SAT 2.3.8
/
Demos
/
StepPlatform Demo ƒ
/
StepPlatform.c
< prev
next >
Wrap
Text File
|
1996-05-11
|
7KB
|
245 lines
// StepPlatform by Nissan Zafrir, based on MyPlatform and StepZkrolly
// Modifications by Ingemar R:
// Scroll-length timed after TickCount in order to make it fast enough on slow Macs
// Replaced ox/oy by gSAT.wind.port->portRect.left and .top (ox/oy are obsolete)
// B/W icons and patterns
// Centered window
// Aligned scrolling to multiples of 8 (to account for a limitation in the 1-bit and 4-bit blitters)
/*
Desirable improvements:
• The man should look better
• Some kind of opponents?
• Ladders?
• Better, more general rect-bounce utilities?
*/
//• main;
#include <SAT.h>
#include "myPlatform.h"
SATPatHandle thepat;
SpritePtr ignoreSp;
Point p;
SpritePtr playerSp;
WindowPtr gWind;
short gVBLInstalled;
Rect r;
enum {
scrollSizeH = 512,
scrollSizeV = 384
};
Point nowOff = {0,0};
#define max(x, y) (x>y?x:y)
#define min(x, y) (x>y?y:x)
#define abs(x) ((x)>0?(x):-(x))
pascal Boolean ScrollScreen()
{
#define sco 8 //the speed of the scroll, number of pixels per *tick*
long startTicks, frameTime = 1;
Rect srcRect;
Point where,were;
// If the player sprite is at the border, scroll!
if ((playerSp->position.h + 64 > scrollSizeH + gSAT.wind.port->portRect.left) ||
(playerSp->position.h < gSAT.wind.port->portRect.left) ||
(playerSp->position.v + 64 > scrollSizeV + gSAT.wind.port->portRect.top) ||
(playerSp->position.v < gSAT.wind.port->portRect.top) )
//gSAT.wind.port->portRect.left/top = ox/oy!
{
were = nowOff;
where = playerSp->position;
where.h -= (scrollSizeH >> 1);
where.v -= (scrollSizeV >> 1);
if (where.h < 0)
where.h = 0;
if (where.v < 0)
where.v = 0;
if (where.h + scrollSizeH > gSAT.offSizeH)
where.h = gSAT.offSizeH - scrollSizeH;
if (where.v + scrollSizeV > gSAT.offSizeV)
where.v = gSAT.offSizeV - scrollSizeV;
where.h &= 0xfff8; // Scroll only to multiples of 8, so we won't confuse the 4-bit and 1-bit blitters!
do
{
startTicks = TickCount();
if (nowOff.h > where.h)
nowOff.h = max(nowOff.h - sco*frameTime, where.h);
if (nowOff.h < where.h)
nowOff.h = min(nowOff.h + sco*frameTime, where.h);
if (nowOff.v > where.v)
nowOff.v = max(nowOff.v - sco*frameTime, where.v);
if (nowOff.v < where.v)
nowOff.v = min(nowOff.v + sco*frameTime, where.v);
SATSetPortScreen();
SetOrigin(nowOff.h, nowOff.v);
gSAT.wind.bounds = gSAT.wind.port->portRect; // Synch gSAT.wind.bounds with the portRect!
srcRect = gSAT.wind.port->portRect;
CopyBits(&gSAT.offScreen.port->portBits, &gSAT.wind.port->portBits, &srcRect, &srcRect, srcCopy, nil);
frameTime = TickCount() - startTicks;
}
while ((nowOff.h != where.h) || (nowOff.v != where.v));
}
// I tried to add this.
// Shouldn't matter anymore - ox and oy are obsolete /IR
// gSAT.ox += nowOff.h-were.h;
// gSAT.oy += nowOff.v-were.v;
} //ScrollScreen
void SetupWind()
{
Rect zr;
SysEnvRec wrld;
//• Since SAT hasn't been initialized, we can't use gSAT.colorFlag but
//• have to check environs ourselves.
if ( noErr != SysEnvirons(1, &wrld))
;//• ignore errors.
// SetRect(&zr, (512-scrollSizeH)/2, 0, (512-scrollSizeH)/2 + scrollSizeH, 0 + scrollSizeV);
// no- center on screen instead!
SetRect(&zr, 0, 0, scrollSizeH, scrollSizeV);
OffsetRect(&zr, (qd.screenBits.bounds.right - qd.screenBits.bounds.left - scrollSizeH) / 2,
(qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - scrollSizeV) / 2);
if ( wrld.hasColorQD )
gWind = NewCWindow(nil, &zr, "\p", false, plainDBox, (WindowPtr)-1L, false, 0);
else
gWind = NewWindow(nil, &zr, "\p", false, plainDBox, (WindowPtr)-1L, false, 0);
} //SetupWind
Boolean IsOptionPressed(void)
{
KeyMap km;
GetKeys(km);
return (km[1] & 4)!=0;
}
Boolean IsPressed(unsigned short k)
{
unsigned char km[16];
GetKeys((unsigned long *)km);
return((km[k>>3]>>(k&7))&1);
}
main ()
{
Rect tempRect;
EventRecord e;
SATInitToolbox();
GetDateTime((unsigned long *)&qd.randSeed);
SATConfigure(true, kVPositionSort, kBackwardCollision, 64);
SetupWind ();
SetRect(&r, 0, 0, 1000, 484); //the offscreen size
SATCustomInit(0, 0, &r, gWind, nil, false, false, false, true, false);
SATSetSpriteRecSize(sizeof(Sprite));
ShowWindow(gSAT.wind.port);
SelectWindow(gSAT.wind.port);
SATHideMBar(gWind);
/* fill the backscreen in a pattren */
SATSetPortBackScreen();
if (IsOptionPressed())
thepat = SATGetPat(SATRand(5)+128); // choose a Pat in Random
else
thepat = SATGetPat(128);//128-brown wall, 130-gray wall pattren
SATPenPat(thepat);
SetRect(&tempRect, 0, 0, gSAT.offSizeH, gSAT.offSizeV+100);
PaintRect(&tempRect);
CopyBits(&(gSAT.backScreen.port)->portBits, &gSAT.offScreen.port->portBits, &gSAT.offScreen.port->portRect, &gSAT.offScreen.port->portRect, srcCopy, nil);
SATBackChanged(&gSAT.offScreen.port->portRect);
SATRedraw();
/*Initialize all sprite units*/
InitPlayerSprite();
InitPlatform();
InitEmptyPlatform();
InitMovPlatform();
InitHMovPlatform();
InitInformationArea();
SATRedraw();
/* SetUp my Sprites */
GetMouse(&p);
playerSp = SATNewSprite(1, p.h, p.v, (void *)&SetupPlayerSprite); // Keep Player Sprite
ignoreSp = SATNewSprite(0, 0, 350, &SetupEmptyPlatform); // the Floor Platform
SetRect(&ignoreSp->hotRect,0,0,gSAT.offSizeH-150,20);
ignoreSp = SATNewSprite(0, 55, 300, &SetupPlatform); // Standing Platform
ignoreSp = SATNewSprite(0, 245, 235, &SetupPlatform); // Standing Platform
ignoreSp = SATNewSprite(55, 355, 200, &SetupMovPlatform); //50=MinV 200=MaxV
//ignoreSp->position.h=30; // I can change the defeults
ignoreSp = SATNewSprite(100, 55, 200, &SetupMovPlatform); //100=MinV 230=MaxV
ignoreSp = SATNewSprite(128, 270, 120, &SetupHMovPlatform); //120=MinH 150=MaxH
ignoreSp->speed.h = 2;
ignoreSp = SATNewSprite(250, 850, 400, &SetupMovPlatform); //50=MinV 200=MaxV
ignoreSp = SATNewSprite(55, 700, 250, &SetupMovPlatform); //50=MinV 200=MaxV
ignoreSp = SATNewSprite(430, 630, 85, &SetupHMovPlatform); //50=MinV 200=MaxV
/*Update the game window once more, so the pattern and what we drawn in DrawInfo are shown. */
SATRedraw();
HideCursor();
SATSoundOff();
#ifndef __MWERKS__
if (gSAT.colorFlag) // Can't do SlotVInstall without CQD
if (IsOptionPressed()) {
InstallVBLCounter();
SATInstallSynch(&VBLCounterProc); //WaitForSync
SysBeep(7);
gVBLInstalled = true;
}
#endif
/* the main loop */
gSAT.wind.bounds = (*gSAT.wind.port).portRect;
SATRedraw();
SATSetPortScreen();
do
{
SATRun(true); //!IsOptionPressed()
ScrollScreen();
if (IsOptionPressed())
DrawProgrammerInfo();
//if (IsOptionPressed()) if (WaitNextEvent ( everyEvent, &e, 10, nil )) ;
} while (! Button ());
/* cleanning up */
SATSetPortScreen();
#ifndef __MWERKS__
if (gVBLInstalled)
RemoveVBLCounter();
#endif
SATSoundShutup();
ShowCursor();
FlushEvents(everyEvent, 0);
} //main